package rediser

import (
	"github.com/go-redis/redis"
	"lowcode_deployment/pkg/config"
)

var (
	Client *redis.Client
	err    error
)

type Options struct {
	Addr string
}

func GetRedisClient(addr, password string) (*redis.Client, error) {
	client := redis.NewClient(&redis.Options{
		Addr:     addr,
		Password: password,
	})

	_, err := client.Ping().Result()
	if err != nil {
		return nil, err
	}
	return client, nil
}

func InitRedis() {
	Client, err = GetRedisClient(config.ENV["REDIS_ADDR"], config.ENV["REDIS_PASSWORD"])
	if err != nil {
		panic(err)
	}
}
